home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1993…ch: Other People's Memory / ADC Developer CD (1993-03) (''Other People's Memory'')_iso / Dev.CD Mar 93.iso / Technical Documentation / Sample Code / DTS.Lib & Samples / DTS.Draw / Help.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-22  |  3.6 KB  |  135 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        Help.c
  5. ** Written by:    Eric Soldan
  6. **
  7. ** Copyright © 1991 Apple Computer, Inc.
  8. ** All rights reserved.
  9. */
  10.  
  11. /* This file contains some sample code for handling dynamic balloon help.  The
  12. ** assumption here, which is valid for DTS.Chat, is that you have controls in
  13. ** the window content, and these controls need balloon help.  Since a DTS.Chat
  14. ** document window consists of two TextEdit controls, this assumption works quite
  15. ** well.  The code walks the control list, looking at the bounding rect of the
  16. ** control.  If the cursor is within that rect, it shows a belloon with the
  17. ** associated help text. */
  18.  
  19.  
  20.  
  21. /*****************************************************************************/
  22.  
  23.  
  24.  
  25. #include "App.h"            /* Get the application includes/typedefs, etc.    */
  26. #include "App.Common.h"        /* Get the stuff in common with rez.            */
  27. #include "App.protos.h"        /* Get the prototypes for application.            */
  28.  
  29. #ifndef __BALLOONS__
  30. #include <Balloons.h>
  31. #endif
  32.  
  33. #ifndef __PROCESSES__
  34. #include <Processes.h>
  35. #endif
  36.  
  37. #ifndef __UTILITIES__
  38. #include "Utilities.h"
  39. #endif
  40.  
  41.  
  42.  
  43. /*****************************************************************************/
  44. /*****************************************************************************/
  45.  
  46.  
  47.  
  48. #pragma segment Main
  49. void    DynamicBalloonHelp(void)
  50. {
  51.     WindowPtr            window, oldPort;
  52.     ProcessSerialNumber    cpsn, fpsn;
  53.     FileRecHndl            frHndl;
  54.     Point                mouseLoc, tip;
  55.     ControlHandle        ctl;
  56.     Rect                rct;
  57.     short                part, message, pos;
  58.     HMMessageRecord        helpMessage;
  59.     Boolean                procsSame;
  60.     static short        lastMessage;
  61.     static short        position[4] = {5, 6, 2, 1};
  62.  
  63.     if (gSystemVersion < 0x0700) return;
  64.         /* The system can't support balloons. */
  65.  
  66.     if ((!HMGetBalloons()) || (!IsAppWindow(FrontWindow()))) {
  67.         lastMessage = 0;
  68.         return;
  69.     }        /* Balloons have been turned off, or it isn't our window anymore. */
  70.  
  71.     HMGetBalloonWindow(&window);
  72.     if (!window)
  73.         lastMessage = 0;
  74.             /* There is no balloon currently, so there is no last message. */
  75.  
  76.     tip = mouseLoc = GetGlobalMouse();
  77.     part = FindWindow(mouseLoc, &window);
  78.     if ((window != FrontWindow()) || (part != inContent)) {
  79.         lastMessage = 0;
  80.         return;
  81.     }        /* We aren't over the content of the front window, so leave. */
  82.  
  83.     GetCurrentProcess(&cpsn);
  84.     GetFrontProcess(&fpsn);
  85.     SameProcess(&cpsn, &fpsn, &procsSame);
  86.     if (!procsSame) {
  87.         lastMessage = 0;
  88.         return;
  89.     }        /* We aren't the front process, so leave. */
  90.  
  91.     GetPort(&oldPort);
  92.     frHndl = (FileRecHndl)GetWRefCon(window);
  93.     SetPort(window);
  94.     GlobalToLocal(&mouseLoc);
  95.  
  96.     ctl = ((WindowPeek)window)->controlList;
  97.     while (ctl) {
  98.         rct = (*ctl)->contrlRect;
  99.         if (PtInRect(mouseLoc, &rct)) break;
  100.         ctl = (*ctl)->nextControl;
  101.     }        /* Find the control that we are over. */
  102.  
  103.     message = 0;
  104.     if (ctl) {}
  105.  
  106.     if (message) {
  107.  
  108.         if (lastMessage != message) {    /* If this balloon isn't current balloon... */
  109.             lastMessage = message;
  110.             helpMessage.hmmHelpType             = khmmStringRes;
  111.             helpMessage.u.hmmStringRes.hmmResID = rDynHelpStrings;
  112.             helpMessage.u.hmmStringRes.hmmIndex = message;
  113.             LocalToGlobalRect(&rct);
  114.             pos = (tip.v > (rct.top + rct.bottom) / 2) ? 2 : 0;
  115.             if (tip.h > (rct.left + rct.right) / 2)
  116.                 ++pos;
  117.             pos = position[pos];
  118.             SetOrigin(0, 0);
  119.             HMShowBalloon(&helpMessage, tip, &rct, nil, 0, pos, kHMRegularWindow);
  120.         }
  121.     }
  122.     else {
  123.         if (lastMessage)
  124.             HMRemoveBalloon();
  125.         lastMessage = 0;
  126.     }
  127.  
  128.     SetOrigin(0, 0);
  129.         /* It is expected that you will modify this code, so I went ahead and set the origin
  130.         ** back to 0,0, in case your modifications alter it.  Currently, I don't change it,
  131.         ** but you might someday. */
  132.  
  133.     SetPort(oldPort);
  134. }
  135.